﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Hotel.Model.admin;
using MD5Hash;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class adminController : ControllerBase
    {
        public adminController(adminBLL adminBLL) 
        {
            AdminBLL = adminBLL;
        }

        public adminBLL AdminBLL { get; }




        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        [HttpPost]
        public int Login(LoginModel loginModel)
        {
            adminModel admin = AdminBLL.Login(loginModel.UserName);
            if (admin==null)
            {

                return 0;//用户不存在
            }
            if (admin.UserPwd!= loginModel.UserPwd) 
            {
                return -1;//密码错误

            }
            else
            {
                return 1;//登录成功
            }
        }



        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="adminModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int adminAdd(adminModel adminModel)
        {
            return AdminBLL.adminAdd(adminModel);
        }









        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="count">总条数</param>
        /// <param name="page">总页数</param>
        /// <param name="UserName"></param>
        /// <param name="index">当前页</param>
        /// <param name="size">每页几条</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult adminList( string? UserName = "", int index = 1, int size = 3)
        {

            int count = 0;
            int page = 0;

            var list= AdminBLL.adminList(out count, out page, UserName, index, size);
            return Ok(new { list= list, count= count, page = page });
        }







        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int adminDel(int id)
        {

            return AdminBLL.adminDel(id);



        }



        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public adminModel adminAll(int id)
        {

            return AdminBLL.adminAll(id);


        }




        /// <summary>
        /// 修改·
        /// </summary>
        /// <param name="adminModel"></param>
        /// <returns></returns>
        [HttpPut]
        public int adminUpd(adminModel adminModel)
        {


            return AdminBLL.adminUpd(adminModel);
        }












    }
}
